<template>
  <div id="app">
    <keep-alive exclude="Goods"><router-view @hide="hide" @show="show" @updateUser="updateuser" /></keep-alive>
    
    <main-tab-bar v-show="isShow" />
  </div>
</template>

<script>
import MainTabBar from "./views/MainTabBar.vue";

export default {
  components: { MainTabBar },
  name: "App",
  data(){
    return {
      isShow:true,
    }
  },
  created() {
    this.initUser()
    
    console.log();
    
  },
  methods:{
    //隐藏tab-bar
    hide(){
      this.isShow = false
    },
    //显示tab-bar
    show(){
      this.isShow = true
    },
    //用户更新信息
    updateuser(){
      this.initUser()
    },
    //初始化用户信息
    initUser(){
      console.log(1)
      let Token = localStorage.getItem("token")
      if (Token) {
      this.$axios({
        url: "users",
        method: "get",
        params: {
          token: Token
        }
      }).then(res => {
        console.log(res.data)
        this.$store.dispatch('DelUserInfo')
        this.$store.dispatch('SaveUserInfo',res.data)
        this.$store.dispatch('ChangeStatus')
      });
    } else {
      alert('登录已过期，请重新登录')
      return this.$router.push('/login')
    }
    }
  }
};
</script>
<style>
@import "./assets/css/base.css";
</style>
